package com.inplaceedit.client.ui.phone;

import com.google.gwt.text.shared.AbstractRenderer;
import com.inplaceedit.shared.dto.PhoneDto;

public class PhoneRenderer extends AbstractRenderer<PhoneDto> {
	private static PhoneRenderer INSTANCE;

	public static PhoneRenderer get() {
		if (INSTANCE == null) {
			INSTANCE = new PhoneRenderer();
		}
		return INSTANCE;
	}

	private PhoneRenderer() {
	}

	@Override
	public String render(final PhoneDto object) {
		String result = "";
		if (object != null) {
			final StringBuilder sb = new StringBuilder();
			sb.append(PhoneTypeRenderer.get().render(object.getType()));
			if (sb.length() > 0) {
				sb.append(":");
			}
			if (object.getNumber() != null && object.getNumber().length() > 0) {
				if (sb.length() > 0) {
					sb.append(" ");
				}
				sb.append(object.getNumber());
			}
			result = sb.toString();
		}
		return result;
	}

}
